package edu.nyp.locationservicesapp.application;

import android.app.Application;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import java.util.List;
import edu.nyp.locationservicesapp.constant.CustomConstant;
import edu.nyp.locationservicesapp.utils.AppUtils;
import edu.nyp.locationservicesapp.utils.CrashHandler;
import edu.nyp.locationservicesapp.utils.LogUtil;

/**
 * 应用Application
 * User:Gaolei  gurecn@gmail.com
 * Date:2016/11/4
 * I'm glad to share my knowledge with you all.
 */
public class TheApplication extends Application {
    private static TheApplication sInstance;
    private static String sCurrentProcessName;
    //获取全局Context
    public static Context getAppContext() {
        return sInstance.getApplicationContext();
    }
    public static List<String> applyFriendNumList;

    @Override
    public void onCreate() {
        super.onCreate();
        sInstance = this;
        LogUtil.d("TheApplication","onCreate");
        Resources res = super.getResources();
        Configuration config = new Configuration();
        config.setToDefaults();
        res.updateConfiguration(config, res.getDisplayMetrics());
        CrashHandler.getInstance().init(); //初始化崩溃时抓log
        //TODO 任何逻辑操作不要在此代码之前执行
        sCurrentProcessName = AppUtils.getCurrentProcessName(getAppContext());
        // 如果是主进程，初始化主进程的相关功能类实例
//        if (isRunningOnMainProcess()) {
            onCreateForMainProcess();
            onInitDataChildThread();
//        }
    }
    /**
     * 是否在主进程运行<br>
     */
    public static boolean isRunningOnMainProcess() {
        return CustomConstant.PROCESS_NAME_MAIN.equals(sCurrentProcessName);
    }

    /**
     * 必须在主线程初始化的操作
     */
    private void onCreateForMainProcess() {
        LauncherModel.initSingleton(this);  //初始化启动相关设置
    }

    /**
     * 可以在子线程初始化的操作
     */
    private void onInitDataChildThread() {
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {

            }
        });
        thread.start();
    }
}
